//
//  HBReadManageView.m
//  HeartBeat
//
//  Created by karong on 2023/9/12.
//

#import "HBReadManageView.h"
#import "HBReadSettingManager.h"

#define NAV_HEIGHT (44 + HBStatusBarHeight)
#define Bottom_HEIGHT (132 + HBSafeAreaBottomHeight)
#define Setting_HEIGHT (336 + HBSafeAreaBottomHeight)
@implementation HBReadManageView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        self.hidden = YES;
        [self addSubview:self.navView];
        [self addSubview:self.enumView];
        [self addSubview:self.setView];
        [self reloadData];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [self addGestureRecognizer:tap];
    }
    return self;
}

- (void)tapAction:(UITapGestureRecognizer *)sender {
    if ([self.delegate respondsToSelector:@selector(tapAction:)]) {
        [self.delegate tapAction:sender];
    }
}

- (void)reloadData{
    [self.navView reloadAllData];
    [self.enumView reloadAllData];
    [self.setView reloadAllViewStyle];
}

- (HBReadNavView *)navView {
    if (!_navView) {
        _navView = [[[NSBundle mainBundle] loadNibNamed:@"HBReadNavView" owner:self options:nil] firstObject];
        _navView.frame = CGRectMake(0, -NAV_HEIGHT, HBScreenWidth, NAV_HEIGHT);
        _navView.hidden = YES;
    }
    return _navView;
}

- (HBReadBottomView *)enumView {
    if (!_enumView) {
        _enumView = [[[NSBundle mainBundle] loadNibNamed:@"HBReadBottomView" owner:self options:nil] firstObject];
        _enumView.frame = CGRectMake(0, HBScreenHeight, HBScreenWidth, Bottom_HEIGHT);
        _enumView.hidden = YES;
        WeakSelf
        _enumView.clickSubItemBlock = ^(NSInteger clickIndex) {
            ///弹出设置页面
            if (clickIndex == 4) {
                [weakSelf showSetView];
            }
        };
    }
    return _enumView;
}

- (HBReadSettingView *)setView {
    if (!_setView) {
        _setView = [[[NSBundle mainBundle] loadNibNamed:@"HBReadSettingView" owner:self options:nil] firstObject];
        _setView.frame = CGRectMake(0, HBScreenHeight, HBScreenWidth, Setting_HEIGHT);
        _setView.hidden = YES;
    }
    return _setView;
}


- (void)clickTapBtn {
    if (self.hidden) {
        [self showAllView];
    }else{
        [self hiddenAllView];
    }
}

- (void)showSetView {
    self.hidden = NO;
    self.setView.hidden = NO;
    [UIView animateWithDuration:0.3 animations:^{
        self.enumView.top = HBScreenHeight + Bottom_HEIGHT;
        self.setView.top = HBScreenHeight - Setting_HEIGHT;
    } completion:^(BOOL finished) {
    }];
}

- (void)hiddenAllView {
    
    [UIView animateWithDuration:0.3 animations:^{
        self.navView.top = -NAV_HEIGHT;
        self.enumView.top = HBScreenHeight + Bottom_HEIGHT;
        self.setView.top = HBScreenHeight + Setting_HEIGHT;
    } completion:^(BOOL finished) {
        self.hidden = YES;
        self.navView.hidden = YES;
        self.enumView.hidden = YES;
        self.setView.hidden = YES;
    }];
}

- (void)showAllView{
    self.hidden = NO;
    self.navView.hidden = NO;
    self.enumView.hidden = NO;
    [UIView animateWithDuration:0.3 animations:^{
        self.navView.top = 0;
        self.enumView.top = HBScreenHeight - Bottom_HEIGHT;
    } completion:^(BOOL finished) {
            
    }];
}
@end
